const formMixin = {
  data () {
    return {
      // form表的的属性配置项
      formConfig: {
        labelCol: { span: 8 },
        wrapperCol: { span: 16 }
      }
    }
  },
  computed: {
    loading () {
      return (btn) => this.$store.state.currBtn === btn
    },
    btndisabled () {
      return this.$store.state.loadding !== 0
    }
  },
  methods: {
    // 重置表单，name是表单的ref名字，可多个
    resetForm (name) {
      name.split(',').forEach(tmp => this.$refs[tmp].resetFields())
    },
    // 表单验证，name是表单的ref名字，可多个
    validateForm (name) {
      let arr = []
      let nameArr = name.split(',')
      nameArr.forEach(name => {
        arr.push(this.$refs[name].validate())
      })
      return new Promise((resolve, reject) => {
        Promise.all(arr)
          .then(res => {
            resolve(true)
          })
          .catch(err => {
            console.error(err)
            resolve(false)
          })
      })
    }
  }
}

export default formMixin
